var idCheckerTimer;
var spanAlert = $get("spanAlert");

function idChecker(id) 
{
    clearTimeout(idCheckerTimer);
    if (id.length == 0)
        spanAlert.innerHTML = "";
    else
    {
        spanAlert.innerHTML = "<span style='color: #555;'>checking...</span>";
        idCheckerTimer = setTimeout("checkIdUsage('" + id + "');", 750);
    }
}

function checkIdUsage(id) 
{
    // initiate the ajax pagemethod call
    // upon completion, the OnSucceded callback will be executed
    PageMethods.IsExistedID(id, OnSucceeded);
}

// Callback function invoked on successful completion of the page method.
function OnSucceeded(result, userContext, methodName) 
{
    if (methodName == "IsExistedID")
    {
        if (result == 1)
            spanAlert.innerHTML = "<span style='color: Green;'>OK</span>";
        else if (result == 0)
            spanAlert.innerHTML = "<span style='color: Red;'>Not existed</span>";
        else
            spanAlert.innerHTML = "<span style='color: Red;'>Invalid ID</span>";
    }
}